from gm.api import *
import talib
import numpy as np


def get_symbol_list(index, now):
    try:
        symbol_list = get_history_constituents(index=index, start_date=now)[0].get('constituents').keys()
        symbol_list_not_suspended = get_history_instruments(symbols=symbol_list, start_date=now, end_date=now)
        symbol_list = [item['symbol'] for item in symbol_list_not_suspended if not item['is_suspended']]
        _symbol_list = symbol_list
        symbol_list = []
        for _ in _symbol_list:
            symbol_list.append(_)
    except:
        print(index)

    return symbol_list


def MACD_CN(close, fastperiod=12, slowperiod=26, signalperiod=9):
    macdDIFF, macdDEA, macd = talib.MACDEXT(close, fastperiod=fastperiod, fastmatype=1, slowperiod=slowperiod,
                                            slowmatype=1, signalperiod=signalperiod, signalmatype=1)
    macd = macd * 2
    return macdDIFF, macdDEA, macd


def get_data_value(data, fields='close'):
    "得到日期值"
    pass
    return np.asarray((data[fields].values))
